package com.xcity.robot.net.packet;

import com.alibaba.fastjson.JSON;

import naga.x.net.impl.pomelo.PomeloPacket;
import naga.x.net.impl.pomelo.body.request.HandshakeRequestBody;
import naga.x.net.impl.pomelo.body.request.HandshakeRequestBody.Sys;
import naga.x.net.impl.pomelo.protocol.Package;

public class HandshakePacket extends PomeloPacket implements BinaryPacket {

	public static final HandshakePacket DEFAULT = new HandshakePacket();
	
	protected HandshakeRequestBody body;
	protected byte[] bytes;
	
	private HandshakePacket() {
		super(-1, Package.TYPE_HANDSHAKE);
		body = new HandshakeRequestBody();
		Sys sys = new Sys();
		sys.setType("js-websocket");
		sys.setProtoVersion("0.0");
		sys.setVersion("0.0");
		body.setSys(sys);
	}

	@Override
	public byte[] toBinary() {
		return bytes != null ? bytes : (bytes = JSON.toJSONBytes(body));
	}
	
}
